﻿using System;
using System.Collections.Generic;
using System.Windows.Input;

namespace Microsoft.Popfly.GameCreator.GameEngine.Events
{
    public class KeyDownEventChecker : IEventChecker
    {
        private Game m_game;
        private List<Key> m_keys;
        public bool FireThisFrame(double elapsedTimeInSeconds, out BehaviorOwner sender, out PGCEventArgs args)
        {
            KeyEventArgs keyArgs = null;

            // Check if we have args for any of the keys tied to this event
            foreach (Key key in m_keys)
            {
                keyArgs = m_game.IsKeyDownThisFrame(key);
                if (keyArgs != null)
                {
                        sender = m_game.CurrentScene;
                        args = new PGCKeyEventArgs(keyArgs);
                        return true;
                }
            }
            sender = null;
            args = null;
            return false ;
        }

        public bool IsOfEventType(string eventType)
        {
            return eventType == "keys";
        }

        public KeyDownEventChecker(Game game, List<Key> keys)
        {
            m_game = game;
            m_keys = keys;
        }
    }
}
